package lk.icta.core.entity;

import lk.icta.common.entity.*;
import org.hibernate.annotations.IndexColumn;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.*;

@Entity
@Table(schema = "ELAND_RAIL")
@NamedQueries({
        @NamedQuery(
                name = "getApplicationsByStateAndRole",
                query = "SELECT l FROM LandApplication l WHERE " +
                        "(1 = :ignoreDS AND l.workflowItem.workflowTask = :state AND l.workflowItem.userRole = :role) OR " +
                        "(0 = :ignoreDS AND l.workflowItem.workflowTask = :state AND l.workflowItem.userRole = :role AND " +
                        "l.dsDivision IN (:DSList))"

        ), @NamedQuery(
        name = "getApplicationsByWorkflowTask",
        query = "SELECT l FROM LandApplication l WHERE " +
                "(1 = :ignoreDS AND l.workflowItem.workflowTask = :task) OR " +
                "(0 = :ignoreDS AND l.workflowItem.workflowTask = :task AND " +
                "l.dsDivision IN (:DSList))"

), @NamedQuery(
        name = "getApplicationsByState",
        query = "SELECT l FROM LandApplication l WHERE " +
                "(1 = :ignoreDS AND l.workflowItem.workflowTask = :state) OR " +
                "(0 = :ignoreDS AND l.workflowItem.workflowTask = :state AND l.dsDivision IN (:DSList)) ORDER BY l.marks ASC"

), @NamedQuery(
        name = "getApplicationsByWorkFlowItemId",
        query = "SELECT l FROM LandApplication l WHERE " +
                "(1 = :ignoreDS AND l.workflowItem.id = :id) OR " +
                "(0 = :ignoreDS AND l.workflowItem.id = :id AND l.dsDivision IN (:DSList)) ORDER BY l.marks ASC"

), @NamedQuery(
        name = "getInitialApplicationsByState",
        query = "SELECT l FROM LandApplication l WHERE " +
                "(1 = :ignoreDS AND l.initialStatus = :state) OR " +
                "(0 = :ignoreDS AND l.initialStatus = :state AND l.dsDivision IN (:DSList)) ORDER BY l.marks ASC"

), @NamedQuery(
        name = "getApplicationsByWorkItemList",
        query = "SELECT l.workflowItem.workflowTask, COUNT(l.id),l.workflowItem.alienationMethod " +
                "FROM LandApplication l WHERE " +
                "(1 = :ignoreDS AND l.workflowItem.id IN (:workItemList)) OR " +
                "(0 = :ignoreDS AND l.workflowItem.id IN (:workItemList) AND  " +
                "l.dsDivision IN (:DSList)) GROUP BY l.workflowItem.workflowTask, l.workflowItem.alienationMethod"

), @NamedQuery(
        name = "getApplicationListByWorkItemList",
        query = "SELECT l FROM LandApplication l WHERE " +
                "(1 = :ignoreDS AND l.workflowItem.id IN (:workItemList)) OR " +
                "(0 = :ignoreDS AND l.workflowItem.id IN (:workItemList) AND  " +
                "l.dsDivision IN (:DSList)) ORDER BY l.lifeCycleInfo.lastUpdatedTimeStamp ASC"

), @NamedQuery(
        name = "getApplicationListByWorkItemListByAlienationMethodId",
        query = "SELECT l FROM LandApplication l WHERE " +
                "(1 = :ignoreDS AND (l.workflowItem.id IN (:workItemList)) AND (l.workflowItem.alienationMethod = :alienationMethodId)) OR " +
                "(0 = :ignoreDS AND (l.workflowItem.id IN (:workItemList)) AND (l.workflowItem.alienationMethod = :alienationMethodId) AND " +
                "l.dsDivision IN (:DSList)) ORDER BY l.lifeCycleInfo.lastUpdatedTimeStamp ASC"

), @NamedQuery(
        name = "getApplicationsByStates",
        query = "SELECT l FROM LandApplication l WHERE " +
                "(1 = :ignoreDS AND l.workflowItem.workflowTask in (:stateSet)) OR " +
                "(0 = :ignoreDS AND l.workflowItem.workflowTask in (:stateSet) AND  l.dsDivision IN (:DSList))"

), @NamedQuery(
        name = "getApplicationsByStatesGn",
        query = "SELECT l FROM LandApplication l WHERE " +
                "(1 = :ignoreDS AND l.workflowItem.workflowTask in (:stateSet) AND l.holder.gnDivision.id = :gnId) OR " +
                "(0 = :ignoreDS AND l.workflowItem.workflowTask in (:stateSet) AND  l.dsDivision IN (:DSList) AND l.holder.gnDivision.id = :gnId)"

), @NamedQuery(
        name = "getApplicationsByAlienationType",
        query = "SELECT l FROM LandApplication l WHERE l.preferredAlienationMethod.id = :alienationType AND " +
                "l.initApplicationId = 0 AND l.dsDivision IN (:DSList)"
), @NamedQuery(
        name = "getRankedApplicationsByState",
        query = "SELECT l FROM LandApplication l WHERE l.initialStatus = :state " +
                "AND l.dsDivision IN (:DSList) " +
                "ORDER BY l.marks ASC "
), @NamedQuery(
        name = "getApplicationsByWorkflowState",
        query = "SELECT l FROM LandApplication l WHERE l.workflowItem.workflowTask = :workflowState AND " +
                "l.dsDivision IN (:DSList)"
), @NamedQuery(
        name = "getSelectedApplicationsByAlienationType",
        query = "SELECT l FROM LandApplication l WHERE l.preferredAlienationMethod.id = :alienationType " +
                "AND l.initApplicationId >= 0  AND l.dsDivision IN (:DSList) " +
                "AND  (l.initialStatus =0 OR l.initialStatus =1 OR l.initialStatus =3 " +
                "OR l.initialStatus =4 OR l.initialStatus =6 )"
), @NamedQuery(
        name = "getApplicationsList",
        query = "SELECT l FROM LandApplication l WHERE   " +
                "(1 = :ignoreDS AND l.initApplicationId >= 0 AND l.initialStatus is null or l.initialStatus <>2 ) OR" +
                "(0 = :ignoreDS AND l.initApplicationId >= 0 AND l.initialStatus is null or l.initialStatus <>2 AND l.dsDivision IN (:DSList)) "
), @NamedQuery(   //todo : why join here?
        name = "getApplicationsByStateAndAM",
        query = "SELECT l FROM LandApplication l join l.alienationMethods ams WHERE l.initialStatus = :state " +
                "AND (l.preferredAlienationMethod.id = :alienationType OR ams.id = :alienationType) " +
                "AND l.dsDivision IN (:DSList) ORDER BY l.marks ASC"
), @NamedQuery(   //todo : why join here?
        name = "getApplicationsByStateAndAlenationMethod",
        query = "SELECT l FROM LandApplication l WHERE " +
                "((1 = :ignoreDS AND l.initialStatus = :state AND l.preferredAlienationMethod.id = :alienationType) OR " +
                "(0 = :ignoreDS AND l.initialStatus = :state AND l.preferredAlienationMethod.id = :alienationType " +
                "AND l.dsDivision IN (:DSList))) ORDER BY l.marks ASC"
), @NamedQuery(
        name = "searchApplicationsOfDSDivisionByPersonName",
        query = "SELECT l FROM LandApplication l WHERE   " +
                "(1 = :ignoreDS AND l.initApplicationId >= 0 AND (l.initialStatus IS NULL OR l.initialStatus <>2) AND l.holder.name LIKE :personName  ) OR" +
                "(0 = :ignoreDS AND l.initApplicationId >= 0 AND (l.initialStatus IS NULL OR l.initialStatus <>2) AND l.holder.name LIKE :personName AND l.dsDivision IN (:DSList)) "
), @NamedQuery(
        name = "searchApplicationsOfDSDivisionByNIC",
        query = "SELECT l FROM LandApplication l WHERE   " +
                "(1 = :ignoreDS AND l.initApplicationId >= 0 AND (l.initialStatus IS NULL OR l.initialStatus <>2) AND l.holder.registrationNumberOrNIC = :nic  ) OR" +
                "(0 = :ignoreDS AND l.initApplicationId >= 0 AND (l.initialStatus IS NULL OR l.initialStatus <>2) AND l.holder.registrationNumberOrNIC = :nic AND l.dsDivision IN (:DSList)) "
), @NamedQuery(
        name = "searchApplicationsByDsId",
        query = "SELECT l FROM LandApplication l WHERE  l.initApplicationId >= 0 " +
                "AND l.dsDivision.id = :DsId " +
                "AND (l.initialStatus IS NULL OR l.initialStatus <> 2)"
), @NamedQuery(
        name = "searchApplicationsByDistrictId",
        query = "SELECT l FROM LandApplication l WHERE  l.initApplicationId >= 0 " +
                "AND l.dsDivision.district.id = :districtId " +
                "AND (l.initialStatus IS NULL OR l.initialStatus <>2)"
), @NamedQuery(
        name = "getApplicationsByStateAndUser",
        query = "SELECT l FROM LandApplication l WHERE " +
                "(l.initialStatus IS NULL OR l.initialStatus <> :state) AND l.holder.slcUser.username = :user "

), @NamedQuery(
        name = "getApplicationsByUser",
        query = "SELECT l FROM LandApplication l WHERE l.initApplicationId > 0 AND l.holder.slcUser.username = :user "

), @NamedQuery(
        name = "getAllApplicationsByWorkflowState",
        query = "SELECT l FROM LandApplication l WHERE l.workflowItem.workflowTask in (:stateSet) "
), @NamedQuery(
        name = "getAllApplicationsByWorkflowStateByAM",
        query = "SELECT l FROM LandApplication l WHERE l.workflowItem.workflowTask in (:stateSet) " +
                "AND (l.preferredAlienationMethod IS NOT NULL AND l.preferredAlienationMethod.id = :alienationType)"
), @NamedQuery(
        name = "getAllApplicationsByWorkflowStateByAMS",
        query = "SELECT l FROM LandApplication l join l.alienationMethods ams WHERE l.workflowItem.workflowTask in (:stateSet)" +
                "AND (ams IS NOT NULL AND ams.id = :alienationType) "
),
        @NamedQuery(
                name = "getApplicationsByProvinceForSlcUsers",
                query = "SELECT l FROM LandApplication l WHERE  l.dsDivision.district.province.id= :provinceId " +
                        "AND l.holder.slcUser.role.id='SLC' " +
                        "AND l.initialStatus =1"
        ), @NamedQuery(
        name = "getApplicationsByStateAndDistrict",
        query = "SELECT l FROM LandApplication l WHERE " +
                "(l.workflowItem.workflowTask = :state And l.dsDivision.district.id = :districtId)"
), @NamedQuery(
        name = "getApplicationsByStateAndDsDivisionId",
        query = "SELECT l FROM LandApplication l WHERE " +
                "(l.workflowItem.workflowTask = :state And l.dsDivision.id = :dsDivisionId)"
), @NamedQuery(
        name = "searchApplicationsByStateByPersonName",
        query = "SELECT l FROM LandApplication l WHERE " +
                "(1 = :ignoreDS AND l.workflowItem.workflowTask = :state AND l.holder.name LIKE :personName  ) OR" +
                "(0 = :ignoreDS AND l.workflowItem.workflowTask = :state AND l.holder.name LIKE :personName AND l.dsDivision IN (:DSList)) "
                /*query = "SELECT l FROM LandApplication l WHERE " +
                         " (l.workflowItem.workflowTask = :state AND l.holder.name LIKE :personName)"    */
), @NamedQuery(
        name = "searchApplicationsByStateByNIC",
        query = "SELECT l FROM LandApplication l WHERE " +
                "(1 = :ignoreDS AND l.workflowItem.workflowTask = :state AND l.holder.registrationNumberOrNIC LIKE :NIC  ) OR" +
                "(0 = :ignoreDS AND l.workflowItem.workflowTask = :state AND l.holder.registrationNumberOrNIC LIKE :NIC AND l.dsDivision IN (:DSList)) "
), @NamedQuery(
        name = "searchAlienationByAlienationSerialNumber",
        query = "SELECT l FROM LandApplication l WHERE " +
                "(1 = :ignoreDS AND l.workflowItem.workflowTask = :state AND l.alienationDetails.id = :ASL  ) OR" +
                "(0 = :ignoreDS AND l.workflowItem.workflowTask = :state AND l.alienationDetails.id = :ASL AND l.dsDivision IN (:DSList)) "
), @NamedQuery(
        name = "searchAlienationByLandSerialNumber",
        query = "SELECT l FROM LandApplication l  WHERE " +
                "(1 = :ignoreDS AND l.workflowItem.workflowTask = :state AND l.alienationDetails.land.id = :serialNumber ) OR" +
                "(0 = :ignoreDS AND l.workflowItem.workflowTask = :state AND l.alienationDetails.land.id = :serialNumber AND l.dsDivision IN (:DSList)) "
), @NamedQuery(
        name = "searchAlienationByReferenceNumber",
        query = "SELECT l FROM LandApplication l  WHERE " +
                "(1 = :ignoreDS AND l.workflowItem.workflowTask = :state AND l.alienationDetails.referenceNo = :alienationNumber ) OR" +
                "(0 = :ignoreDS AND l.workflowItem.workflowTask = :state AND l.alienationDetails.referenceNo = :alienationNumber AND l.dsDivision IN (:DSList)) "
), @NamedQuery(
        name = "searchAlienationByMethod",
        query = "SELECT l FROM LandApplication l  WHERE " +
                "(1 = :ignoreDS AND l.workflowItem.workflowTask = :state AND l.preferredAlienationMethod.id = :alienationMethodId ) OR" +
                "(0 = :ignoreDS AND l.workflowItem.workflowTask = :state AND l.preferredAlienationMethod.id = :alienationMethodId AND l.dsDivision IN (:DSList)) "
), @NamedQuery(
        name = "searchAllAlienationByMethod",
        query = "SELECT l FROM LandApplication l  WHERE " +
                "(1 = :ignoreDS AND l.workflowItem.workflowTask = :state) OR" +
                "(0 = :ignoreDS AND l.workflowItem.workflowTask = :state AND l.dsDivision IN (:DSList)) "
)

})
public class LandApplication extends BaseEntity {

    private static final Logger logger = LoggerFactory.getLogger(LandApplication.class);

    public enum State {
        /**
         * 0 - A newly entered init Application- can be edited
         */
        INITIAL_APPLICATION_DATA_ENTRY("Initial Application - Data Entry", "මුලික ඉල්ලුම් පත්‍ර - දත්ත ඇතුළත් කළ", "Initial Application - Data Entry (ta)"),
        /**
         * 1 - Approved init  Application
         */
        INITIAL_APPLICATION_APPROVED("Initial Application - Approved", "මුලික ඉල්ලුම් පත්‍ර - අනුමත කළ", "Initial Application - Approved (ta)"),
        /**
         * 2 - initial Application closed when detailed application is added
         */
        INITIAL_APPLICATION_CLOSED("Initial Application - Closed", "මුලික ඉල්ලුම් පත්‍ර - නිමවූ", "Initial Application - Closed (ta)"),
        /**
         * 3 - A rejected init Application
         */
        INITIAL_APPLICATION_REJECTED("Initial Application - Rejected", "මුලික ඉල්ලුම් පත්‍ර - ප්‍රතික්ෂේප කළ", "Initial Application - Rejected (ta)"),

        /**
         * 4 - A backup complete application before edit
         */
        COMPLETED_APPLICATION_ARCHIVED("සම්පූර්ණ වූ ඉල්ලුම් පත්‍ර -Archived", "Complete Application -Archived (si)", "Complete Application -Archived (ta)");

        //TODO to be removed
        /**
         * 4 - A newly entered detailed Application- can be edited
         */
        //DETAILED_FORM_DATA_ENTRY,  ///TODO : move below to workflow
        /*    //5
        DETAILED_FORM_APPROVED, //by ords
        //6
        DETAILED_FORM_REJECTED,   //by ords
        //7                                                                       sudo /etc/init.d/tomcat6 start
        INTERVIEW_DATA_ENTRY,  //by lo
        //8
        INTERVIEW_COMPLETED, // by lo ,application registration number generated
        //9
        OBJECTION_DATA_ENTRY,  //by ords or lo //TODO : put two entries
        //10
        OBJECTION_HANDLING_COMPLETED, // by ords
        //11
        OBJECTION_HANDLING_APPROVED, //by plc
        //12
        DETAILED_FORM_FINALIZED,  //capture objections, finalize and complete by plc
        //13
        LAND_ALLOCATED,
        //14
        LAND_ALLOCATION_APPROVED,
        //15
        LAND_ALLOCATION_REJECTED,
        //16
        ACCEPTED_AND_COMPLETED,  //accepted by applicant
        //17
        REJECTED_AND_ARCHIVED,  //rejected by applicant
        //18
        NOT_SUBMITTED_AND_ARCHIVED,  // not received by due date
        //19
        APPROVE_ACCEPTED_AND_COMPLETED_APPLICATION,  //applications in this state will be eligible to enter to the  work flow
        //20
        APPROVE_REJECTED_AND_ARCHIVED_APPLICATION,
        //21
        APPROVE_NOT_SUBMITTED_APPLICATION,
        //22
        FULLY_APPROVED,
        //23
        SIGNED_PRINTED_ALIENATION_DOCUMENT,
        //24
        UNSIGNED_PRINTED_ALIENATION_DOCUMENT,
        //25
        SIGNED_ALIENATION_DOCUMENT_APPROVED,
        //26
        CONDITION_SATISFIED*/

        private String nameInEn;
        private String nameInSi;
        private String nameInTa;

        public String getNameInEn() {
            return nameInEn;
        }

        public void setNameInEn(String nameInEn) {
            this.nameInEn = nameInEn;
        }

        public String getNameInSi() {
            return nameInSi;
        }

        public void setNameInSi(String nameInSi) {
            this.nameInSi = nameInSi;
        }

        public String getNameInTa() {
            return nameInTa;
        }

        public void setNameInTa(String nameInTa) {
            this.nameInTa = nameInTa;
        }

        State(String nameInEn, String nameInSi, String nameInTa) {
            this.nameInEn = nameInEn;
            this.nameInSi = nameInSi;
            this.nameInTa = nameInTa;
         }
    }

//    @Column(nullable = true)
//    private WorkflowTask workflowState;

    @ManyToOne
    @JoinColumn(name = "workflowItem", nullable = true)
    private WorkflowItem workflowItem;

    /**
     * Date of the from submit
     */
    @Column(nullable = true)
    @Temporal(value = TemporalType.DATE)
    private Date submitDate;

    @ManyToOne
    @JoinColumn(nullable = true)
    private LandUsage landUsage;

    @OneToOne(cascade = {CascadeType.ALL})
    @JoinColumn
    private Alienation alienationDetails;

    @ManyToMany(fetch = FetchType.EAGER)
    @IndexColumn(name = "INDEX_COL")
    @JoinTable(schema = "ELAND_RAIL", name = "New_Alienation")
    private List<AlienationMethod> alienationMethods;

    /**
     * The DS Divisions list that a land is requested by the applicant
     */
    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(schema = "ELAND_RAIL")
    private Set<DSDivision> dsDivisions;

    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(schema = "ELAND_RAIL")
    private List<Land> landList;

    /**
     * Users DS division
     */
    @ManyToOne
    @JoinColumn(nullable = false)
    private DSDivision dsDivision;

    /**
     * Applicant type can be either person or institute
     * Person       = 1
     * Institute    = 0
     */
    /*  @Column(nullable = false)
 private int applicantType; */

    @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE})
    @JoinColumn(nullable = false)
    private Holder holder;

    @Column(nullable = true)
    private Double landExpectedExtent;

    @Column(nullable = true)
    private String nominatedSuccessorName;

    @Column(nullable = true)
    private String presentUserName;

    @Column(nullable = true)
    private String developmentStatus;

    @Column(nullable = true)
    private boolean permitHolderOccupiedTheLand;

    @Column(nullable = true)
    private String purpose;

    @ManyToOne
    private AlienationMethod preferredAlienationMethod;

    //todo: rename to init app status
    @Enumerated
    private State initialStatus;

    @Column(nullable = true)
    private long initApplicationId;

    //todo: to be removed
    @Column(nullable = true)
    private BigDecimal annualIncome;

    @Column(nullable = true)
    private String occupation;

    @Column(nullable = true)
    private String informationAboutTheProject;

    @Column(nullable = true, columnDefinition = "text")
    private String comment;

    @Column(nullable = true)
    private String planNo;

    @Column(nullable = true)
    private String lotNo;

    @Column(nullable = true)
    private int noOfDependents;

    @Column(nullable = true)
    private int durationOfResidency;

    @Column(nullable = true)
    private boolean heritageOrLegallyDeservedLand;

    @Column(nullable = true)
    private int specialStrengths;

    @Column(nullable = true)
    private int abilityToDevelopTheLand;

    @Column(nullable = true)
    private int socialActivities;

    @Column(nullable = true)
    private int civilStatus;

    @Column(nullable = true)
    private int residencialType;

    @Column(nullable = true)
    private int marks;

    @Column(nullable = true)
    private boolean legallyDeservedProperty;

    @Embedded
    private LifeCycleInfo lifeCycleInfo = new LifeCycleInfo();

    @Transient
    private List<Document> documentList;

    @Column(nullable = true)
    private String refNumber;

    @Column(nullable = true)
    private String agreementNo;

    @Column(nullable = true)
    private String objections;

    @Column(nullable = true)
    private CommunicationMethod communicationMethod;

    @Column(nullable = true)
    private String communicationLanguage;

    @Column(nullable = true)
    @Temporal(value = TemporalType.DATE)
    private Date dueDate;

    @Column(nullable = true)
    private int letterCount;

    @Transient
    private int nextAction;

    public Alienation getAlienationDetails() {
        return alienationDetails;
    }

    public void setAlienationDetails(Alienation alienationDetails) {
        this.alienationDetails = alienationDetails;
    }

    public LandUsage getLandUsage() {
        return landUsage;
    }

    public void setLandUsage(LandUsage landUsage) {
        this.landUsage = landUsage;
    }

    public Date getSubmitDate() {
        return submitDate;
    }

    public void setSubmitDate(Date submitDate) {
        this.submitDate = submitDate;
    }

    public Double getLandExpectedExtent() {
        return landExpectedExtent;
    }

    public void setLandExpectedExtent(Double landExpectedExtent) {
        this.landExpectedExtent = landExpectedExtent;
    }

    public String getPurpose() {
        return purpose;
    }

    public void setPurpose(String purpose) {
        this.purpose = purpose;
    }

    public State getInitialStatus() {
        return initialStatus;
    }

    public void setInitialStatus(State status) {
        this.initialStatus = status;
    }

    public long getInitApplicationId() {
        return initApplicationId;
    }

    public void setInitApplicationId(long initApplicationId) {
        this.initApplicationId = initApplicationId;
    }

    public Set<DSDivision> getDsDivisions() {
        return dsDivisions;
    }

    public void setDsDivisions(Set<DSDivision> dsDivisions) {
        this.dsDivisions = dsDivisions;
    }

    /*  public String getNameOfTheSpouse() {
            return nameOfTheSpouse;
        }

        public void setNameOfTheSpouse(String nameOfTheSpouse) {
            this.nameOfTheSpouse = nameOfTheSpouse;
        }
    */
    public String getNominatedSuccessorName() {
        return nominatedSuccessorName;
    }

    public void setNominatedSuccessorName(String nominatedSuccessorName) {
        this.nominatedSuccessorName = nominatedSuccessorName;
    }

    public String getPresentUserName() {
        return presentUserName;
    }

    public void setPresentUserName(String presentUserName) {
        this.presentUserName = presentUserName;
    }

    public String getDevelopmentStatus() {
        return developmentStatus;
    }

    public void setDevelopmentStatus(String developmentStatus) {
        this.developmentStatus = developmentStatus;
    }

    public boolean isPermitHolderOccupiedTheLand() {
        return permitHolderOccupiedTheLand;
    }

    public void setPermitHolderOccupiedTheLand(boolean permitHolderOccupiedTheLand) {
        this.permitHolderOccupiedTheLand = permitHolderOccupiedTheLand;
    }

    public BigDecimal getAnnualIncome() {
        return annualIncome;
    }

    public void setAnnualIncome(BigDecimal annualIncome) {
        this.annualIncome = annualIncome;
    }

    public String getOccupation() {
        return occupation;
    }

    public void setOccupation(String occupation) {
        this.occupation = occupation;
    }

    public String getPlanNo() {
        return planNo;
    }

    public void setPlanNo(String planNo) {
        this.planNo = planNo;
    }

    public String getInformationAboutTheProject() {
        return informationAboutTheProject;
    }

    public void setInformationAboutTheProject(String informationAboutTheProject) {
        this.informationAboutTheProject = informationAboutTheProject;
    }

    public LifeCycleInfo getLifeCycleInfo() {
        return lifeCycleInfo;
    }

    public void setLifeCycleInfo(LifeCycleInfo lifeCycleInfo) {
        this.lifeCycleInfo = lifeCycleInfo;
    }

    /*   public WorkflowTask getWorkflowTask() {
        return workflowState;
    }

    public void setWorkflowTask(WorkflowTask workflowState) {
        this.workflowState = workflowState;
    }*/

    public AlienationMethod getPreferredAlienationMethod() {
        return preferredAlienationMethod;
    }

    public void setPreferredAlienationMethod(AlienationMethod preferredAlienationMethod) {
        this.preferredAlienationMethod = preferredAlienationMethod;
    }

    public int getNoOfDependents() {
        return noOfDependents;
    }

    public List<Document> getDocumentList() {
        return documentList;
    }

    public void setNoOfDependents(int noOfDependents) {
        this.noOfDependents = noOfDependents;
    }

    public void setDocumentList(List<Document> documentList) {
        this.documentList = documentList;
    }

    public int getDurationOfResidency() {
        return durationOfResidency;
    }

    public void setDurationOfResidency(int durationOfResidency) {
        this.durationOfResidency = durationOfResidency;
    }

    public boolean isHeritageOrLegallyDeservedLand() {
        return heritageOrLegallyDeservedLand;
    }

    public void setHeritageOrLegallyDeservedLand(boolean heritageOrLegallyDeservedLand) {
        this.heritageOrLegallyDeservedLand = heritageOrLegallyDeservedLand;
    }

    public int getSpecialStrengths() {
        return specialStrengths;
    }

    public void setSpecialStrengths(int specialStrengths) {
        this.specialStrengths = specialStrengths;
    }

    public int getAbilityToDevelopTheLand() {
        return abilityToDevelopTheLand;
    }

    public void setAbilityToDevelopTheLand(int abilityToDevelopTheLand) {
        this.abilityToDevelopTheLand = abilityToDevelopTheLand;
    }

    public int getSocialActivities() {
        return socialActivities;
    }

    public void setSocialActivities(int socialActivities) {
        this.socialActivities = socialActivities;
    }

    public int getCivilStatus() {
        return civilStatus;
    }

    public void setCivilStatus(int civilStatus) {
        this.civilStatus = civilStatus;
    }

    public int getResidencialType() {
        return residencialType;
    }

    public void setResidencialType(int residencialType) {
        this.residencialType = residencialType;
    }

    public boolean isLegallyDeservedProperty() {
        return legallyDeservedProperty;
    }

    public void setLegallyDeservedProperty(boolean legallyDeservedProperty) {
        this.legallyDeservedProperty = legallyDeservedProperty;
    }


    public int getMarks() {
        return marks;
    }

    public void setMarks(int marks) {
        this.marks = marks;
    }

    public String getAgreementNo() {
        return agreementNo;
    }

    public void setAgreementNo(String agreementNo) {
        this.agreementNo = agreementNo;
    }

    public String getLotNo() {
        return lotNo;
    }

    public void setLotNo(String lotNo) {
        this.lotNo = lotNo;
    }

    public List<Land> getLandList() {
        return landList;
    }

    public void setLandList(List<Land> landList) {
        this.landList = landList;
    }

    /* public WorkflowTask getRejectState() {
        int stateId = 0;
        if (workflowState == null || workflowState.getId() < 0) {
            return null;
        }

        stateId = (workflowState.getId() + 1) * (-1);

        for (WorkflowTask ws : WorkflowTask.values()) {
            if (ws.getId() == stateId) {
                return ws;
            }
        }
        return null; // No rejected state for this state
    }


    public WorkflowTask findNextState() {
        WorkflowTask nextState;
        if (workflowState == null) {
            return null;
        } else if (workflowState.getId() < 0) {
            //nextState = findBackwardState();
            //  nextState = WorkflowTask.COMPLETED;
            return null;
        } else {
            nextState = findForwardState();
        }
        return nextState;
    }

    public WorkflowTask findForwardState() {
        if (alienationMethod == null) {
            logger.debug("No Alienation method found");
        }
        logger.debug("Alienation Method Id : {}", alienationMethod.getId());
        logger.debug("Alienation Method workflow : {}", alienationMethod.getWorkflow1().toString());
        EnumSet<WorkflowTask> workflow = alienationMethod.getWorkflow1();
        Iterator<WorkflowTask> wsIterator = workflow.iterator();

        WorkflowTask nextItem = null;
        int count = 0;
        while (wsIterator.hasNext()) {
            if (count == 1) {
                nextItem = wsIterator.next();
                logger.debug("Next Workflow state of Application : {}", nextItem.toString());
                break;
            }
            if (wsIterator.next() == workflowState) {
                logger.debug("Workflow state of Application : {}", workflowState.toString());
                count = 1;
            }
        }
        return nextItem;
    }*/

    public List<AlienationMethod> getAlienationMethods() {
        return alienationMethods;
    }

    public void setAlienationMethods(List<AlienationMethod> alienationMethods) {
        this.alienationMethods = alienationMethods;
    }

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public String getRefNumber() {
        return refNumber;
    }

    public void setRefNumber(String refNumber) {
        this.refNumber = refNumber;
    }

    public Holder getHolder() {
        return holder;
    }

    public void setHolder(Holder holder) {
        this.holder = holder;
    }

    public DSDivision getDsDivision() {
        return dsDivision;
    }

    public void setDsDivision(DSDivision dsDivision) {
        this.dsDivision = dsDivision;
    }

    public String getObjections() {
        return objections;
    }

    public void setObjections(String objections) {
        this.objections = objections;
    }

    public CommunicationMethod getCommunicationMethod() {
        return communicationMethod;
    }

    public void setCommunicationMethod(CommunicationMethod communicationMethod) {
        this.communicationMethod = communicationMethod;
    }

    public String getCommunicationLanguage() {
        return communicationLanguage;
    }

    public void setCommunicationLanguage(String communicationLanguage) {
        this.communicationLanguage = communicationLanguage;
    }

    public Date getDueDate() {
        return dueDate;
    }

    public void setDueDate(Date dueDate) {
        this.dueDate = dueDate;
    }

    public WorkflowItem getWorkflowItem() {
        return workflowItem;
    }

    public void setWorkflowItem(WorkflowItem workflowItem) {
        this.workflowItem = workflowItem;
    }

    public int getLetterCount() {
        return letterCount;
    }

    public void setLetterCount(int letterCount) {
        this.letterCount = letterCount;
    }

    public int getNextAction() {
        return nextAction;
    }

    public void setNextAction(int nextAction) {
        this.nextAction = nextAction;
    }
}

